<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_health extends Admin_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('Health_mdl');
		$this->uid = $this->user_login->is_logged_in() ? $this->user_login->get_user_id() : 0;
	}

	public function index()
	{
		$this->shicai_list();
	}

	public function health_list($cid = '')
	{
		$keywords = $this->input->post('keywords');
		$page = max(1, intval($this->input->post('pageNum')));
		$limit = 18; //每页显示数
		$offset = ($page - 1) * $limit;


		//分页
		$data['totalCount'] = 10000;
		$data['numPerPage'] = $limit;
		$data['currentPage'] = $page;
		$data['keywords'] = $keywords;
		$data['cid'] = $cid;
		if ($keywords)
		{
			$data['health_list'] = $this->Health_mdl->get_health_search($keywords, $offset, $limit)->result_array();
		}
		else
		{
			$data['health_list'] = $this->Health_mdl->get_health_list($cid, $offset, $limit)->result_array();
		}
		
		$this->load->view('health', $data);
	}

	public function health_add($cid = '')
	{
		if ($this->input->post('submit') == 'ok')
		{
			$arr = array(
				'title' => $this->input->post('title'),
				'description' => $this->input->post('description'),
				'uid' => $this->uid,
				'status' => $this->input->post('status'),
				'cid' => $this->input->post('cid_cid'),
				'youyi' => $this->input->post('youyi'),
				'youyi_group' => $this->input->post('youyi_group'),
				'jinji' => $this->input->post('jinji'),
				'jinji_group' => $this->input->post('jinji_group'),
				'views' => $this->input->post('views')
			);
			$result = $this->Health_mdl->health_insert($arr);
			$this->_jui_message('操作成功');
		}
		else
		{
			$this->load->library('category');
			$cate = $this->category->fetchOne($cid);
			$data['health_info'] = array(
				'title' => '',
				'cid' => $cid,
				'cateName' => $cate['cateName'],
				'description' => '',
				'youyi' => '',
				'jinji' => '',
				'youyi_group' => '',
				'jinji_group' => '',
				'views' => '0',
				'status' => ''
			);
			$this->load->view('health_edit', $data);
		}
	}
	public function health_edit($id = '')
	{
		if(empty($id) || !is_numeric($id))
		{
			show_error('失败：参数有误');
			exit();
		}

		if ($this->input->post('submit') == 'ok')
		{
			$arr = array(
				'title' => $this->input->post('title'),
				'description' => $this->input->post('description'),
				'uid' => $this->uid,
				'cid' => $this->input->post('cid_cid'),
				'youyi' => $this->input->post('youyi'),
				'youyi_group' => $this->input->post('youyi_group'),
				'jinji' => $this->input->post('jinji'),
				'jinji_group' => $this->input->post('jinji_group'),
				'views' => $this->input->post('views'),
				'status' => $this->input->post('status')
			);

			$result = $this->Health_mdl->health_update($arr, $id);
			$this->_jui_message('操作成功');
		}
		else
		{
			$data['health_info'] = $this->Health_mdl->get_health_by_id($id);
			/** 不存在? */
			if(!$data['health_info'])
			{
				//redirect('health/category');
				exit();
			}

			$this->load->view('health_edit', $data);
		}

	}
	
	public function health_del($id = '')
	{
		//$result = $this->Article_mdl->article_delete($id);
		$this->_jui_message('删除成功');
	}


}

/* End of file admin_article.php */
/* Location: ./application/controllers/manage/admin_article.php */